package com.atguigu.srb.core.controller.api;


import com.atguigu.srb.common.result.Result;
import com.atguigu.srb.core.pojo.entity.BorrowInfo;
import com.atguigu.srb.core.service.BorrowInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 借款信息表 前端控制器
 * </p>
 *
 * @author lsyandwh
 * @since 2022-12-02
 */
@Api(tags = "借款申请")
@RestController
@RequestMapping("/api/core/borrowerInfo")
public class ApiBorrowInfoController {

    @Autowired
    private BorrowInfoService borrowInfoService;

    @ApiOperation("获取借款人借款申请状态")
    @GetMapping("/getBorrowerInfoStatus")
    public Result getBorrowerInfoStatus(HttpServletRequest request){

        String userId = request.getHeader("userId");
        Integer status = borrowInfoService.getBorrowerInfoStatus(userId);

        return Result.ok().data("borrowInfoStatus",status);
    }

    @ApiOperation("借款申请提交")
    @PostMapping("/save")
    public Result save(@RequestBody BorrowInfo borrowInfo,HttpServletRequest request){

        System.out.println("borrowInfo = " + borrowInfo);
        String userId = request.getHeader("userId");
        borrowInfoService.saveBorrowInfo(borrowInfo,userId);

        return Result.ok().message("提交成功");
    }

}

